﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 注册登录
{
    public partial class LoginWindow : Form
    {
        public LoginWindow()
        {
            InitializeComponent();
        }

        private void loginButton_Click(object sender, EventArgs e)
        {
            string name = accountTextbox.Text;
            string password = passwordTextbox.Text;

            string sql = "select * from users where userName=@user";
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@user",name)
            };
            DataSet data = Connection.SqlQuery(sql,parameters);

            if(data.Tables["Info"].Rows.Count < 1)
            {
                MessageBox.Show("用户不存在");
                passwordTextbox.Text = "";
                accountTextbox.Text = "";
                return;
            }
            else if(data.Tables["Info"].Rows[0][1].ToString()==password)
            {
                MessageBox.Show("登录成功");
                this.Hide();
                ManageWindow manageWindow = new ManageWindow(this);
                manageWindow.Show();
            }
            else
            {
                MessageBox.Show("密码不正确");
                passwordTextbox.Text = "";
            }
        }

        private void regButton_Click(object sender, EventArgs e)
        {
            this.Hide();
            RegisterWindow registerWindow = new RegisterWindow(this);
            registerWindow.Show();
        }
    }
}
